using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.Hr.Attendance.Rule;
using HengTong.Model.Db.Hr.Attendance;


namespace HengTong.ViewModel.Hr.SysAttendanceSubsidyRuleVms
{
    public partial class SysAttendanceSubsidyRuleListVm : BaseListVm<SysAttendanceSubsidyRuleView, SysAttendanceSubsidyRuleSearcher>
    {

        protected override IEnumerable<IGridColumn<SysAttendanceSubsidyRuleView>> InitGridHeader()
        {
            return new List<GridColumn<SysAttendanceSubsidyRuleView>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.RuleType),
                this.MakeGridHeader(x => x.EffectiveStartDate),
                this.MakeGridHeader(x => x.EffectiveEndDate),
                this.MakeGridHeader(x => x.IsEnabled),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeader(x => x.AttendanceTimeConditionEnabled),
                this.MakeGridHeader(x => x.MinAttendanceHours),
                this.MakeGridHeader(x => x.CheckinTimeConditionEnabled),
                this.MakeGridHeader(x => x.CheckinStartDayOffset),
                this.MakeGridHeader(x => x.CheckinStartTime),
                this.MakeGridHeader(x => x.CheckinEndDayOffset),
                this.MakeGridHeader(x => x.CheckinEndTime),
                this.MakeGridHeader(x => x.CheckoutTimeConditionEnabled),
                this.MakeGridHeader(x => x.CheckoutStartDayOffset),
                this.MakeGridHeader(x => x.CheckoutStartTime),
                this.MakeGridHeader(x => x.CheckoutEndDayOffset),
                this.MakeGridHeader(x => x.CheckoutEndTime),
                this.MakeGridHeader(x => x.CalculationType),
                this.MakeGridHeader(x => x.FixedAmount),
                this.MakeGridHeader(x => x.CalculationFormula),
                this.MakeGridHeader(x => x.MaxAmount),
                this.MakeGridHeader(x => x.MinAmount),
                this.MakeGridHeader(x => x.ShiftName),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysAttendanceSubsidyRuleView> GetSearchQuery()
        {
            var query = DC.Set<SysAttendanceSubsidyRule>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckEqual(Searcher.IsEnabled, x=>x.IsEnabled)
                .CheckEqual(Searcher.ShiftId, x=>x.ShiftId)
                .Select(x => new SysAttendanceSubsidyRuleView
                {
				    ID = x.ID,
                    Name = x.Name,
                    RuleType = x.RuleType,
                    EffectiveStartDate = x.EffectiveStartDate,
                    EffectiveEndDate = x.EffectiveEndDate,
                    IsEnabled = x.IsEnabled,
                    Remark = x.Remark,
                    AttendanceTimeConditionEnabled = x.AttendanceTimeConditionEnabled,
                    MinAttendanceHours = x.MinAttendanceHours,
                    CheckinTimeConditionEnabled = x.CheckinTimeConditionEnabled,
                    CheckinStartDayOffset = x.CheckinStartDayOffset,
                    CheckinStartTime = x.CheckinStartTime,
                    CheckinEndDayOffset = x.CheckinEndDayOffset,
                    CheckinEndTime = x.CheckinEndTime,
                    CheckoutTimeConditionEnabled = x.CheckoutTimeConditionEnabled,
                    CheckoutStartDayOffset = x.CheckoutStartDayOffset,
                    CheckoutStartTime = x.CheckoutStartTime,
                    CheckoutEndDayOffset = x.CheckoutEndDayOffset,
                    CheckoutEndTime = x.CheckoutEndTime,
                    CalculationType = x.CalculationType,
                    FixedAmount = x.FixedAmount,
                    CalculationFormula = x.CalculationFormula,
                    MaxAmount = x.MaxAmount,
                    MinAmount = x.MinAmount,
                    ShiftName = x.Shift.Name,
                })
                .OrderBy(x => x.ID);
            return query;
        }
    }

    public class SysAttendanceSubsidyRuleView : SysAttendanceSubsidyRule{
        [Display(Name = "班次名称")]
        public String ShiftName { get; set; }

    }
}
